/**
 * @Project: Runer
 * @Title: NetworkUtil.java
 * @Package com.runlooker.runer.util
 * @author town
 * @date 2014-5-8 下午10:13:31
 * @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
 * @version V1.0
 */
package com.runlooker.runer.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;

/**
 * 
 * 网络工具
 * 
 * 
 * @ClassName NetworkUtil
 * @Description 模块描述
 * @author town
 * @Date 2014-5-8
 */
public class NetworkUtil {
	private final static String tag = NetworkUtil.class.getSimpleName();
	public static final int NETWORN_NONE = 0;// 无网
	public static final int NETWORN_WIFI = 1;// wifi
	public static final int NETWORN_MOBILE = 2; // 3G移动数据

	public static int getNetworkState(Context context) {
		ConnectivityManager connManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		// Wifi
		State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.getState();
		if (state == State.CONNECTED || state == State.CONNECTING) {
			return NETWORN_WIFI;
		}
		try {
			state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
					.getState();
			if (state == State.CONNECTED || state == State.CONNECTING) {
				return NETWORN_MOBILE;
			}

		} catch (Exception e) {
		}

		return NETWORN_NONE;
	}

}
